﻿'// ========================================================================= '
'// ------------------------------------------------------------------------- '
'//!				\file		CM_Survey1.vb
'			        \date		june 2010
'			        \author		TNick
'
'			        \brief		
'
'
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   This file is considered universal knowledge. No restrictions
'   are imposed; use as you see fit.
'   Please read ReadMe.txt and Licence.txt in root folder
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'   
'
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
'//
'//
'//
'//
'//  IMPORTS     ------------------------------------------------------------ '
#Region "Imports"

Imports System
Imports System.IO
Imports Microsoft.Win32
Imports System.Xml.Serialization

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Customization
Imports Autodesk.AutoCAD.PlottingServices
Imports Autodesk.AutoCAD.Colors

#End Region
'//  IMPORTS     ============================================================ '
'//
'//
'//
'//
'//  DEFINITIONS    --------------------------------------------------------- '
<Assembly: CommandClass(GetType(CM_Survey1))> 



#Region "Public Structures"


'// --------------------------------------------------------------------- '
'// defines the settings for this module
Public Structure SURVSTG

    Public place_holder As Integer

End Structure
'// ===================================================================== '

'// --------------------------------------------------------------------- '
'// an observation for forward intersection
Public Structure S_FRWE
    '// the location where measurement was taken
    Public sPtName As String
    '// horizontal angle (arbitrary reference direction)
    Public dHAng As Double
    '// vertical angle (Double.Max means it was not measured)
    '// it always refers to zenithal(?) angle
    Public dVAng As Double
End Structure

'// ===================================================================== '

#End Region



'//  DEFINITIONS    ========================================================= '
'//
'//
'//
'//
'//  DATA    ---------------------------------------------------------------- '


'//  DATA    ================================================================ '
'//
'//
'//
'//
'//  CLASS    --------------------------------------------------------------- '

Public Class CM_Survey1
    Inherits CModule


    '// --------------------------------------------------------------------- '
    '// DATA
#Region "Public Constants"
    '// name as displayed in various places
    Public Const sAPPNAME As String = "Survey_1"
    '// version as displayed in various places
    Public Const sAPPVER As String = "1.0.0.0"

    '// Command. Brings up the settings dialog
    Public Const sCMD_SETTINGS As String = "TNIK_SURV1_STG"
    '// Command. Imports known points
    Public Const sCMD_IMP_K As String = "TNIK_SURV1_IMP_K"



    '// name of the block used for known points
    Public Const sBLKN_KNOWN As String = "TNIK_KNPT"
    '// name of the layer used for known points
    Public Const sLAYN_KNOWN As String = "PT_Known"
    '// name of the layer used for command blocks
    Public Const sLAYN_CMD As String = "Commands"



    '// number of observation attributes
#End Region

#Region "Public Data"
    '// short description
    Public Shared sAPPTIP As String
    '// the settings
    Public Shared Stgs As SURVSTG

#End Region
    '// ===================================================================== '

#Region "Private general purpose Functions"


    '// --------------------------------------------------------------------- '
    '// This function saves current settings
    Private Shared Sub SaveSett()
        Try

        Catch ex As System.Exception
            Debug.Print("Survey_1 SaveSett Exception " & ex.Message)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// This function loads current settings
    Private Shared Sub GetSett()
        Try

        Catch ex As System.Exception
            Debug.Print("Survey_1 GetSett Exception " & ex.Message)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// This function shows current settings
    Private Shared Function PrintStg(ByRef lcStg As SURVSTG) As String
        Return (vbNewLine & CMain._T(TX.CSTG) & sAPPNAME & ": " & vbNewLine & _
 _
              CMain._T(TX.MODEL) & ":" & vbNewLine & _
          vbNewLine & vbNewLine)

    End Function
    '// ===================================================================== '

#End Region

#Region "Common interface" ' -----------------------

    '// --------------------------------------------------------------------- '
    '// a new instance is created
    Public Sub New()
        Try
            sAPPTIP = CMain._T(TX.SRV_TIP)
            Return
        Catch ex As System.Exception
            CMain.DebugException(ex)
            Return
        End Try
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// the module is asked to terminate
    Public Overrides Function Terminate() As Boolean
        Try
            SaveSett()
            Return True
        Catch ex As System.Exception
            CMain.DebugException(ex)
            Return False
        End Try
    End Function
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// the module is informed about application start-up
    Public Shared Sub DoPrereq()
        Try
            ' this function is called at application start-up in order to 
            ' allow applications to do any prerequisites
            ' there is no instance of this class at this time
            GetSett()
        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
        Return
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// create the user interface for this module
    Public Shared Sub DoCUI( _
     ByRef pcs As CustomizationSection, _
     ByRef mg As MacroGroup)
        ' this function is called when a CUI is builded in order to
        ' allow any application specifics
        Try
#If HARDCORE_CUI Then
            If CApp.cuiCl Is Nothing Then Exit Try
            CApp.cuiCl.AddMacro(sCMD_SETTINGS, "SRV1_Settings")

            CApp.cuiCl.AddToolbar( _
                sAPPNAME, _
                Application.MainWindow.Location.X, _
                100 + MIDS.SURV1 * 30)
            CApp.cuiCl.AddToolbarBtn(CMain._T(TX.SETTINGS), sCMD_SETTINGS)

#Else
			Dim mm1 As MenuMacro = Nothing
			mm1 = New MenuMacro(mg, sCMD_SETTINGS, "^C^C" & sCMD_SETTINGS, "ID_" & sCMD_SETTINGS)

			Dim tbBtn As ToolbarButton = Nothing
			Dim newTb As Toolbar = New Toolbar(sAPPNAME, pcs.MenuGroup)
			newTb.ElementID = "EID_TNIK_SURV1"
			newTb.ToolbarOrient = ToolbarOrient.floating
			newTb.ToolbarVisible = ToolbarVisible.show
            newTb.XCoordinate = Application.MainWindow.Location.X
            newTb.YCoordinate = 100 + MIDS.SURV1 * 30


			tbBtn = New ToolbarButton(newTb, -1) ' separator

			tbBtn = New ToolbarButton(newTb, -1)
			tbBtn.Name = CMain._T(tx.SETTINGS)
			tbBtn.MacroID = "ID_" & sCMD_SETTINGS

#End If
        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// the module is asked to tell it's name
    Public Shared Function GetName() As String
        Return sAPPNAME
    End Function
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// the module is asked to tell about itself
    Public Shared Function GetDescription() As String
        Dim sOut As String = sAPPNAME
        Try
            Dim cIni As New IniWork(CApp.sAppPath & CMain.APPSTG)
            If cIni.HasErrors = True Then Exit Try
            sOut = cIni.Read(sAPPNAME, CMain.DESCRKEY & _
                             CMain.eAppLang.ToString, sAPPNAME)
        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
        Return sOut
    End Function
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// the module is asked to tell about itself
    Public Shared Sub GetInfos(ByRef sName As String, ByRef sVer As String, ByRef sTip As String)
        sName = sAPPNAME
        sVer = sAPPVER
        sTip = sAPPTIP
    End Sub
    '// ===================================================================== '

#End Region

#Region "GENERIC FUNCTIONS"

    Public Shared pt_buf() As FSK_PT3D
    Public Shared fwi() As S_FRWE
    Public Shared ptb_u As Long

    '// ------------------------------------------------------------------------- '
    Public Function Del_ImpPt_Known( _
            ByRef acDoc As Document, _
            ByRef pt As FSK_PT3D, _
            ByRef lcStg As PT3DSTG) As Boolean

        Try
            If (ptb_u = pt_buf.Length) Then
                ReDim Preserve pt_buf(0 To pt_buf.Length + 127)
            End If
            pt_buf(ptb_u) = pt
            ptb_u = ptb_u + 1
        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
        Return True

    End Function
    '// ========================================================================= '


    '// --------------------------------------------------------------------- '
    Private Shared Function EnshureLayers( _
        ByRef acDoc As Document, _
        ByRef acTrans As Transaction) _
        As Boolean

        Dim bRet As Boolean = False
        Try
            '// see if this drawing has required layers
            '// get a reference to table of blocks
            Dim acLy As LayerTableRecord = Nothing
            Dim acLyTbl As LayerTable = DirectCast( _
             acTrans.GetObject(acDoc.Database.LayerTableId, OpenMode.ForWrite),  _
             LayerTable)
            Dim acCol As New Autodesk.AutoCAD.Colors.Color()

            If (acLyTbl.Has(sLAYN_KNOWN) = False) Then
                acLy = New LayerTableRecord()
                acLy.Name = sLAYN_KNOWN
                acLy.Color = Color.FromColorIndex(ColorMethod.ByAci, 41)
                acLyTbl.Add(acLy)
                acTrans.AddNewlyCreatedDBObject(acLy, True)
            End If

            bRet = True
        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
        Return bRet
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// Creates block definition for forward intersection in specificed drawing
    Public Shared Function CBlkDef_ForwardInt( _
      ByRef acDoc As Document) _
      As Boolean

        Dim db As Database = acDoc.Database
        Dim ed As Editor = acDoc.Editor
        Dim acBlkTbl As BlockTable
        Dim acBlkNewBlock As BlockTableRecord
        Dim bRes As Boolean = False

        Using acTrans As Transaction = _
            db.TransactionManager.StartTransaction()
            Try
                If (EnshureLayers(acDoc, acTrans) = False) Then Exit Try

                acBlkTbl = DirectCast( _
                    acTrans.GetObject(db.BlockTableId, OpenMode.ForWrite),  _
                    BlockTable)
                If (acBlkTbl.Has(sBLKN_KNOWN) = False) Then

                    Dim oidTxSty As ObjectId
                    '// Get the text style that we're going to use
                    Dim acTxStyTbl As TextStyleTable = DirectCast( _
                        acTrans.GetObject(db.TextStyleTableId, OpenMode.ForRead),  _
                        TextStyleTable)
                    oidTxSty = acTxStyTbl("Standard")
                    '// Create a new (basic, empty) block
                    acBlkNewBlock = New BlockTableRecord()

                    ' Step 1: Set the block name and base point of the 
                    ' block definition.
                    acBlkNewBlock.Name = sBLKN_KNOWN
                    acBlkNewBlock.Origin = New Point3d(0, 0, 0)


                    ' Step 2: Add the block table record to block table.
                    acBlkTbl.Add(acBlkNewBlock)
                    acTrans.AddNewlyCreatedDBObject(acBlkNewBlock, True)
                    acBlkNewBlock.UpgradeOpen()

                    ' Step 3: create graphics to identify this block
                    Dim acText As DBText = New DBText()
                    acText.SetDatabaseDefaults(db)
                    acText.TextString = "C"
                    acText.Position = New Point3d(0, 0, 0)
                    acText.Height = 0.02
                    acBlkNewBlock.AppendEntity(acText)
                    acTrans.AddNewlyCreatedDBObject(acText, True)
                    acText = Nothing

                    ' Step 4: create graphics to tell the type
                    acText = New DBText()
                    acText.SetDatabaseDefaults(db)
                    acText.TextString = "Forward intersection"
                    acText.Position = New Point3d(0, 0.02, 0)
                    acText.Height = 0.02
                    acBlkNewBlock.AppendEntity(acText)
                    acTrans.AddNewlyCreatedDBObject(acText, True)
                    acText = Nothing

                    ' Step 3: Create attributes
                    Dim acAtr As AttributeDefinition
                    '// Suplemental space between attributes

                    ' Step 3.1: Name of the point to be generated
                    acAtr = New AttributeDefinition()
                    acAtr.SetDatabaseDefaults()
                    acAtr.Prompt = CMain._T(TX.NAME)
                    acAtr.TextString = "?"
                    acAtr.Tag = CM_3DPoints.sPTOA_NAME
                    acAtr.Invisible = False
                    acAtr.Verifiable = False
                    acAtr.Preset = False
                    acAtr.Constant = False
                    acAtr.Position = New Point3d(0.02, 0, 0)
                    acAtr.Layer = sLAYN_CMD
                    acAtr.TextStyle = oidTxSty
                    acBlkNewBlock.AppendEntity(acAtr)
                    acTrans.AddNewlyCreatedDBObject(acAtr, True)

                    ' Open the block table for write.
                    acBlkNewBlock.UpgradeOpen()
                    acTrans.Commit()
                    bRes = True
                Else
                    Debug.Print("CBlkDef_KnownPoint called for a block tht already exists")
                    bRes = True
                End If

            Catch ex As System.Exception
                CMain.DebugException(ex)
                acTrans.Abort()
            Finally

            End Try
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End Using

        Return bRes
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// Creates the proper block definition in specified drawing
    Public Shared Function CBlkDef_KnownPoint( _
      ByRef acDoc As Document) _
      As Boolean

        Dim db As Database = acDoc.Database
        Dim ed As Editor = acDoc.Editor
        Dim acBlkTbl As BlockTable
        Dim acBlkNewBlock As BlockTableRecord
        Dim bRes As Boolean = False

        Using acTrans As Transaction = _
            db.TransactionManager.StartTransaction()
            Try
                If (EnshureLayers(acDoc, acTrans) = False) Then Exit Try

                acBlkTbl = DirectCast( _
                    acTrans.GetObject(db.BlockTableId, OpenMode.ForWrite),  _
                    BlockTable)
                If (acBlkTbl.Has(sBLKN_KNOWN) = False) Then

                    Dim oidTxSty As ObjectId
                    '// Get the text style that we're going to use
                    Dim acTxStyTbl As TextStyleTable = DirectCast( _
                        acTrans.GetObject(db.TextStyleTableId, OpenMode.ForRead),  _
                        TextStyleTable)
                    oidTxSty = acTxStyTbl("Standard")
                    '// Create a new (basic, empty) block
                    acBlkNewBlock = New BlockTableRecord()

                    ' Step 1: Set the block name and base point of the 
                    ' block definition.
                    acBlkNewBlock.Name = sBLKN_KNOWN
                    acBlkNewBlock.Origin = New Point3d(0, 0, 0)


                    ' Step 2: Add the block table record to block table.
                    acBlkTbl.Add(acBlkNewBlock)
                    acTrans.AddNewlyCreatedDBObject(acBlkNewBlock, True)

                    ' Open the block table for write.
                    acBlkNewBlock.UpgradeOpen()


                    ' Step 3: Create a triangle entity - the marker
                    Dim acTri As Polyline = New Polyline
                    acTri.SetDatabaseDefaults()
                    acTri.AddVertexAt(0, New Point2d(0, 0.2), 0, 0, 0)
                    acTri.AddVertexAt(0, New Point2d(0.0173, -0.01), 0, 0, 0)
                    acTri.AddVertexAt(0, New Point2d(-0.0173, -0.01), 0, 0, 0)
                    acTri.Closed = True
                    acTri.Layer = sLAYN_KNOWN
                    acBlkNewBlock.AppendEntity(acTri)
                    acTrans.AddNewlyCreatedDBObject(acTri, True)


                    ' Step 4: Create a point entity - the marker
                    Dim acPt As DBPoint = New DBPoint
                    acPt.SetDatabaseDefaults()
                    acPt.Position = New Point3d(0, 0, 0)
                    acPt.Layer = sLAYN_KNOWN
                    acBlkNewBlock.AppendEntity(acPt)
                    acTrans.AddNewlyCreatedDBObject(acPt, True)

                    ' Step 5: Create attributes
                    Dim acAtr As AttributeDefinition
                    '// Suplemental space between attributes

                    '   5.1 Name
                    acAtr = New AttributeDefinition()
                    acAtr.SetDatabaseDefaults()
                    acAtr.Prompt = CMain._T(TX.NAME)
                    acAtr.TextString = "?"
                    acAtr.Tag = CM_3DPoints.sPTOA_NAME
                    acAtr.Invisible = False
                    acAtr.Verifiable = False
                    acAtr.Preset = False
                    acAtr.Constant = False
                    acAtr.Position = New Point3d(0.02, 0, 0)
                    acAtr.Layer = sLAYN_KNOWN
                    acAtr.TextStyle = oidTxSty
                    acBlkNewBlock.AppendEntity(acAtr)
                    acTrans.AddNewlyCreatedDBObject(acAtr, True)

                    '   5.2 Z - Height
                    acAtr = New AttributeDefinition()
                    acAtr.SetDatabaseDefaults()
                    acAtr.Prompt = "Z"
                    acAtr.TextString = "0.000"
                    acAtr.Tag = CM_3DPoints.sPTOA_Z
                    acAtr.Invisible = True
                    acAtr.Verifiable = False
                    acAtr.Preset = False
                    acAtr.Constant = False
                    acAtr.Position = New Point3d(0.02, -0.01, 0)
                    acAtr.Layer = sLAYN_KNOWN
                    acAtr.TextStyle = oidTxSty
                    acBlkNewBlock.AppendEntity(acAtr)
                    acTrans.AddNewlyCreatedDBObject(acAtr, True)

                    '   5.3 Code - Description
                    acAtr = New AttributeDefinition()
                    acAtr.SetDatabaseDefaults()
                    acAtr.Prompt = CMain._T(TX.CODE)
                    acAtr.TextString = ""
                    acAtr.Tag = CM_3DPoints.sPTOA_CODE
                    acAtr.Invisible = False
                    acAtr.Verifiable = False
                    acAtr.Preset = False
                    acAtr.Constant = False
                    acAtr.Position = New Point3d(0.02, -0.02, 0)
                    acAtr.Layer = sLAYN_KNOWN
                    acAtr.TextStyle = oidTxSty
                    acBlkNewBlock.AppendEntity(acAtr)
                    acTrans.AddNewlyCreatedDBObject(acAtr, True)


                    acTrans.Commit()
                    bRes = True
                Else
                    Debug.Print("CBlkDef_KnownPoint called for a block tht already exists")
                    bRes = True
                End If

            Catch ex As System.Exception
                CMain.DebugException(ex)
                acTrans.Abort()
            Finally

            End Try
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End Using

        Return bRes
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// Creates the points in pt_buf buffer
    Public Shared Function InsBlkRef_KnownPoint( _
        ByRef acDoc As Document) As Boolean

        Dim bRet As Boolean = False
        Dim db As Database = acDoc.Database
        Dim ed As Editor = acDoc.Editor

        Dim sForm As String
        If (String.IsNullOrEmpty(CM_3DPoints.Stgs.sFormCoord)) Then
            sForm = "0.000"
        Else
            sForm = CM_3DPoints.Stgs.sFormCoord
        End If

        Using acTrans As Transaction = _
            db.TransactionManager.StartTransaction()
            Try
                '// get a reference to table of blocks
                Dim acBlkTbl As BlockTable = DirectCast( _
                 acTrans.GetObject(db.BlockTableId, OpenMode.ForRead),  _
                 BlockTable)

                Call EnshureLayers(acDoc, acTrans)

                If (acBlkTbl.Has(sBLKN_KNOWN) = False) Then
                    If CBlkDef_KnownPoint(acDoc) = False Then
                        Exit Try
                    End If
                End If

                ' Get Model space (is just a block)
                Dim acBlkModel As BlockTableRecord = DirectCast( _
                    acTrans.GetObject( _
                        acBlkTbl(BlockTableRecord.ModelSpace), _
                        OpenMode.ForWrite),  _
                    BlockTableRecord)

                '// Get the type of the object
                Dim id_B As ObjectId = acBlkTbl(sBLKN_KNOWN)
                Dim iCnt As Integer = 0
                For Each pt As FSK_PT3D In pt_buf
                    iCnt = iCnt + 1
                    If (iCnt > ptb_u) Then Exit For

                    ' Create a block reference
                    Dim br As BlockReference = _
                        New BlockReference( _
                            New Point3d(pt.East, pt.North, pt.Height), _
                            id_B)
                    br.SetDatabaseDefaults()
                    ' Add the block reference to Model space
                    acBlkModel.AppendEntity(br)
                    acTrans.AddNewlyCreatedDBObject(br, True)

                    ' open the template block
                    Dim Block As BlockTableRecord = DirectCast( _
                        br.BlockTableRecord.GetObject(OpenMode.ForRead),  _
                        BlockTableRecord)

                    If Block.HasAttributeDefinitions = False Or _
                        (Block.Database Is Nothing) Then
                        CMain.AlertUser(CMain._T(TX.ERR_WRONGBLK))
                        Exit Try
                    End If

                    '// Iterate in attributes
                    For Each Id As ObjectId In Block
                        Dim Ent As Entity = DirectCast( _
                            Id.GetObject(Autodesk.AutoCAD.DatabaseServices. _
                                         OpenMode.ForRead),  _
                            Entity)

                        '// actual entity
                        If TypeOf Ent Is AttributeDefinition Then
                            Dim AttDef As AttributeDefinition = _
                                DirectCast(Ent, AttributeDefinition)
                            Dim AttRef As New AttributeReference
                            AttRef.SetPropertiesFrom(AttDef)
                            AttRef.SetAttributeFromBlock(AttDef, br.BlockTransform)
                            Select Case AttRef.Tag.ToUpper
                                Case CM_3DPoints.sPTOA_NAME
                                    If String.IsNullOrEmpty(pt.Name) = False Then
                                        AttRef.TextString = pt.Name
                                    End If
                                Case CM_3DPoints.sPTOA_Z
                                    AttRef.TextString = pt.Height.ToString(sForm)
                                Case CM_3DPoints.sPTOA_CODE
                                    If String.IsNullOrEmpty(pt.Descr) = False Then
                                        AttRef.TextString = pt.Descr
                                    End If
                            End Select
                            '// add this to the drawing
                            br.AttributeCollection.AppendAttribute(AttRef)
                            acTrans.AddNewlyCreatedDBObject(AttRef, True)
                        End If
                    Next
                Next


                acTrans.Commit()
                bRet = True
            Catch ex As System.Exception
                acTrans.Abort()
                CMain.DebugException(ex)
            End Try
        End Using
        GC.Collect()
        GC.WaitForPendingFinalizers()
        Return bRet
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// data parsing fuction for Forward Intersection
    Public Shared Function Del_DataInVal( _
            ByRef sLine As String, _
            ByRef sTokList() As String) As Boolean

        Dim bRet As Boolean = True
        Try
            If (sTokList Is Nothing) Then Exit Try
            If (sTokList.Length = 0) Then Exit Try
            bRet = False
            If (sTokList.Length = 1) Or (sTokList.Length > 3) Then
                Autodesk.AutoCAD.ApplicationServices.Application. _
                    ShowAlertDialog("Proper format for forward intersection data is" & vbNewLine & _
                                    "<Known point number> <Horizontal angle> <Vertical angle>" & vbNewLine & _
                                    "Vertical angle part is optional")
                Exit Try
            End If

            If (fwi Is Nothing) Then
                ReDim fwi(0 To 0)
            Else
                ReDim Preserve fwi(0 To fwi.Length)
            End If
            fwi(fwi.Length - 1).sPtName = sTokList(0)
            If (CMain.GetDbl(sTokList(1), fwi(fwi.Length - 1).dHAng) = False) Then
                Exit Try
            End If
            If (sTokList.Length = 3) Then
                '// vertical angle present
                If (CMain.GetDbl(sTokList(2), fwi(fwi.Length - 1).dVAng) = False) Then
                    Exit Try
                End If
            End If
            bRet = True
        Catch ex As System.Exception
            Return False
        End Try
        If (bRet = False) Then
            fwi = Nothing
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End If
        Return bRet
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// Create a new forward intersection
    Public Shared Function InsBlkRef_ForwardInt( _
        ByRef acDoc As Document) As Boolean

        Try

            '// we need to get the data from user
            Dim dlgGet As New CD_DataIn
            dlgGet.bAllowEmptyInput = False
            dlgGet.bSendEmptyLines = False
            dlgGet.kbValidator = New Del_DataInVal(AddressOf Del_DataInVal)
            ReDim dlgGet.inl_sep(0 To 0)
            dlgGet.inl_sep(0) = " "c
            dlgGet.inl_sep(1) = vbTab
            If Application.ShowModalDialog(dlgGet) Then
                If (fwi Is Nothing) Then
                    '// we have ignition

                End If
            End If

        Catch ex As System.Exception
            CMain.DebugException(ex)
        End Try

    End Function
    '// ===================================================================== '


#End Region

#Region "C O M M A N D S"

    '// --------------------------------------------------------------------- '
    <CommandMethod(sCMD_SETTINGS)> _
    Public Sub Show_Settings()
        Try

            Dim StgD As CST_Survey1 = New CST_Survey1
            Application.ShowModelessDialog(StgD)
        Catch ex As System.Exception
            CMain.PopUpExc()
            CMain.DebugException(ex)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    <CommandMethod(sCMD_IMP_K)> _
    Public Sub Imp_Known()
        Try
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            If (acDoc Is Nothing) Then Exit Try

            Dim fdlg As Windows.Forms.OpenFileDialog = _
                New Windows.Forms.OpenFileDialog()

            fdlg.Title = CMain._T(TX.IMPORT)
            fdlg.Filter = CMain._T(TX.EXCFILES) & " (*.xls)|*.xls|" & _
                          CMain._T(TX.TXTFILES) & " (*.txt)|*.txt|" & _
                          CMain._T(TX.ALLFILES) & " (*.*)|*.*"
            fdlg.FilterIndex = 2
            fdlg.RestoreDirectory = False
            fdlg.CheckFileExists = True
            If fdlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
                If (CBlkDef_KnownPoint(acDoc)) Then
                    Dim del As Del_ImpPt
                    ReDim pt_buf(0 To 127)
                    ptb_u = 0
                    del = New Del_ImpPt(AddressOf Del_ImpPt_Known)
                    CM_3DPoints.ImportFile(fdlg.FileName, CM_3DPoints.Stgs, del)
                    If (ptb_u > 0) Then
                        InsBlkRef_KnownPoint(acDoc)
                    End If
                End If
            End If
        Catch ex As System.Exception
            CMain.PopUpExc()
            CMain.DebugException(ex)
        End Try
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '

#End Region

End Class
'//  CLASS    =============================================================== '
'//
'//
'//
'//
'//  FUNCTIONS    ----------------------------------------------------------- '

'//  FUNCTIONS    =========================================================== '
'//
'//
'//
'//
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
